package 剑指offer.zw_21_调整数组顺序使奇数位于偶数前面;

class Solution {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4};
        int[] exchange = exchange(nums);
        for (int i : exchange) {
            System.out.print(i + " ");
        }
    }

    public static int[] exchange(int[] nums) {
        int left = 0, right = nums.length - 1;
        while (left < right) {
            while (nums[left] % 2 == 1 && left < right) {
                left++;
            }
            while (nums[right] % 2 == 0 && left < right) {
                right--;
            }
            int temp = nums[right];
            nums[right] = nums[left];
            nums[left] = temp;
        }
        return nums;
    }

}
